<template>
    <div>
        <div class="menuadd">
            <el-button round type="primary" @click="addcate" plain>添加</el-button>
        </div>

        <!-- 渲染列表数据   :data="catelist"  绑定到下面-->
        <el-table :data="catelist" style="width: 100%;margin-bottom: 20px;" row-key="id"
            :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">

            <el-table-column prop="id" label="序号" width="180">
            </el-table-column>

            <el-table-column prop="catename" label="分类名称" width="180"></el-table-column>

            <el-table-column prop="img" label="分类图片" width="280">
                <!-- 获取  图片值 -->
                <template v-slot="$prop">
                    <img height="100px" v-if="$prop.row.img != ''" :src="$prop.row.img" alt="">
                </template>
            </el-table-column>

            <el-table-column prop="status" label="分类状态">
                <template v-slot="$prop">

                    <el-button v-if="$prop.row.status == 1" round type="primary" size="mini" plain>正常</el-button>
                    <el-button v-else round type="warning" size="mini" plain>禁用</el-button>
                </template>
            </el-table-column>

            <el-table-column label="操作">
                <template v-slot="$prop">
                    <el-button round type="primary" size="mini" @click="change($prop.row)" plain>编辑</el-button>
                    <el-button round type="danger" size="mini" @click="del($prop.row.id)" plain>删除</el-button>
                </template>
            </el-table-column>

        </el-table>
        <v-dialog :info="info" ref="son" />
    </div>
</template>


<script>
import { mapActions, mapState } from "vuex"
import vDialog from "./dialog.vue"
export default {
    computed: {
        ...mapState("cate", ["catelist"])
    },
    methods: {
        ...mapActions("cate", ["getcatelist"]),
        addcate() {
            this.info.isShow = true
        },
        // 删除
        del(id) {
            this.$confirms(() => {
                this.$Api.catedelete({ id }).then((res) => {
                    console.log(res, 111111);
                    if (res.code == 200) {
                        this.$message.success(res.msg)
                        // 更新
                        this.getcatelist()
                    } else {
                        this.$message.error(res.msg)
                    }
                })
            })
            console.log(id, "删除");
        },
        // 编辑
        change(cateedit) {
            // console.log(cateedit,123);
            // console.log(this.$refs.son);
            this.$refs.son.setInfo(cateedit)
            this.info.isShow = true
        }
    },
    mounted() {
        // 调用这个函数
        this.getcatelist()
    },
    data() {
        return {
            info: {
                isShow: false
            }
        }
    },
    components: { vDialog }
}

</script>


<style leng='less' scoped>

</style>